<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<%@ include file="/common/extjs.jsp"%>
<title>单位分部分项工程管理</title>
<!-- ext javascript includes -->
<script type="text/javascript"
	src="${ctx}/ext/ux/treegrid/TreeGridSorter.js"></script>
<script type="text/javascript"
	src="${ctx}/ext/ux/treegrid/TreeGridColumnResizer.js"></script>
<script type="text/javascript"
	src="${ctx}/ext/ux/treegrid/TreeGridNodeUI.js"></script>
<script type="text/javascript"
	src="${ctx}/ext/ux/treegrid/TreeGridLoader.js"></script>
<script type="text/javascript"
	src="${ctx}/ext/ux/treegrid/TreeGridColumns.js"></script>
<script type="text/javascript" src="${ctx}/ext/ux/treegrid/TreeGrid.js"></script>
<script type="text/javascript" src="${ctx}/ext/ui/contractForm.js"></script>
<script type="text/javascript">
	Ext.ns("Pengtu.Ext");
	Pengtu.Ext.DrawcontractPanel = Ext.extend(Pengtu.Ext.ContractPanel, {
		deleteURL : '${ctx}/project/drawcontract!delete.action?id=',
		saveURL : '${ctx}/project/drawcontract!save.action',
		loadURL : '${ctx}/project/drawcontract!getDrawContruct.action?drawId=',
		createForm : function() {
			this.fp = new Ext.FormPanel({
				labelWidth : 100, // label settings here cascade unless overridden
				frame : true,
				id : this.id,
				title : this.title,
				bodyStyle : 'padding:5px 5px 0',
				width : this.width,
				items : [new Ext.TabPanel({
			        width:450,
			        activeTab: 0,
			        frame:true,
			        border:false,
			        defaults:{autoHeight: true},
			        items:[
			            { title: '基本信息',
			              layout:'form',	
			              frame :true,
			              defaults : {
							labelWidth : 100,
							width : 180
						   },
						  defaultType : 'textfield',
						  items:[{
							xtype : 'hidden',
							name : 'id'
							}, {
								fieldLabel : '标段名称',
								name : 'contractOrder',
								allowBlank : false,
								blankText:'请输入标段名称'
							}, {
								fieldLabel : '标段编号',
								name : 'contractCode',
								allowBlank : false,
								blankText:'请输入合同编号'
							}, {
								fieldLabel : '起点桩号',
								name : 'startPegNum'
							}, {
								fieldLabel : '终点桩号',
								name : 'endPegNum'
							},{
								xtype:'combo',
								fieldLabel : '是否主要工程',
								name : 'principal',
								store:new Ext.data.ArrayStore({
							        fields: ['value', 'label'],
							        data : [['0','是'],['1','否']]
							    }),
							    displayField:'label',
							    valueField :'value',
							    hiddenName :"principal",
					            typeAhead: true,
							    mode: 'local',
							    triggerAction: 'all',
							    lazyRender:true
							}, {
								fieldLabel : '技术评定',
								xtype : 'hidden',
								name : 'qualityGrade'
							},  {
								fieldLabel : '工程位置',
								xtype:'textarea',
								name : 'location'
							},{
								xtype:'textarea',
								fieldLabel : '备注',
								name : 'remark'
							} 
				       ]},
				       { title: '规模概况',
				              layout:'form',	
				              frame :true,
				              defaults : {
								labelWidth : 100,
								width : 180
							   },
							  defaultType : 'textfield',
							  items:[{
									fieldLabel : '工程概算(万元):',
									name : 'planInvestmentTotal',
									allowBlank : false,
									xtype:'numberfield', 
									blankText:'请输入工程概算'
								}, {
									fieldLabel : '建安投资(万元)：',
									name : 'buildInvestment',
									xtype:'numberfield', 
									allowBlank : false,
									blankText:'请输入建安投资'
								}, {
									fieldLabel : '拟建规模宽',
									name : 'toBuildWidth'
								}, {
									fieldLabel : '总里程数(公里)',
									name : 'toBuildLenTotal'
								}, 
								 {
									fieldLabel : '建设规模',
									xtype:'textarea',
									name : 'buildBackgroud'
								},
								 {
									fieldLabel : '主要工程量',
									xtype:'textarea',
									name : 'primeQuantity'
								},
								 {
									xtype:'textarea',
									fieldLabel : '备注',
									name : 'remark2'
								} 
					       ]},
					       { title: '技术标准',
					              layout:'form',	
					              frame :true,
					              defaults : {
									labelWidth : 100,
									width : 180
								   },
								  defaultType : 'textfield',
								  items:[{
										xtype:'combo',
										fieldLabel : '技术标准',
										name : 'techGrade',
										store:new Ext.data.ArrayStore({
									        fields: ['value', 'label'],
									        data : [['0','高速公路'],['1','一级公路'],['2','二级公路'],['3','三级公路'],['4','四级公路']]
									    }),
									    displayField:'label',
									    valueField :'value',
									    hiddenName :"techGrade",
							            typeAhead: true,
									    mode: 'local',
									    triggerAction: 'all',
									    lazyRender:true,
									    allowBlank : false,
										blankText:'请选择技术标准'
									},{
										xtype:'combo',
										fieldLabel : '行政级别',
										name : 'socialLevel',
										store:new Ext.data.ArrayStore({
									        fields: ['value', 'label'],
									        data : [['0','村道'],['1','乡道'],['2','县道'],['3','省道'],['4','国道']]
									    }),
									    displayField:'label',
									    valueField :'value',
									    hiddenName :"socialLevel",
							            typeAhead: true,
									    mode: 'local',
									    triggerAction: 'all',
									    lazyRender:true,
									    allowBlank : false,
										blankText:'请选择行政级别'
									},{
										fieldLabel : '面层厚度(cm)',
										name : 'roadsurfacePly'
									}, {
										fieldLabel : '路基宽度(m)',
										name : 'roadsurfaceWidth'
									}, {
										fieldLabel : '车道数',
										name : 'lanesNum'
									}, {
										fieldLabel : '设计速度(km/h)',
										name : 'designSpeed'
									},{
										xtype:'combo',
										fieldLabel : '路面类型',
										name : 'roadType',
										store:new Ext.data.ArrayStore({
									        fields: ['value', 'label'],
									        data : [['11','沥青混凝土'],['12','水泥混凝土'],['21','沥青贯入式'],['22','沥青碎石'],['23','沥青表面处治'],['99','其它']]
									    }),
									    displayField:'label',
									    valueField :'value',
									    hiddenName :"roadType",
							            typeAhead: true,
									    mode: 'local',
									    triggerAction: 'all',
									    lazyRender:true,
									    allowBlank : false,
										blankText:'请选择路面类型'
									},{
										xtype:'textarea',
										fieldLabel : '备注',
										name : 'remark3'
									} 
						       ]}
			        ]
			    })]
			})
			return this.fp;
		}
	});
	
	Pengtu.Ext.SubunitPanel = Ext.extend(Pengtu.Ext.ContractPanel, {
		deleteURL:'${ctx}/project/sub/subunit!delete.action?id=',
		saveURL : '${ctx}/project/sub/subunit!save.action',
		loadURL : '${ctx}/project/sub/subunit!getSubunit.action?id=',
		createForm : function() {
			this.fp = new Ext.FormPanel({
				labelWidth : 100, // label settings here cascade unless overridden
				frame : true,
				id : this.id,
				title : this.title,
				bodyStyle : 'padding:5px 5px 0',
				width : this.width,
				defaults : {
					labelWidth : 100,
					width : 180
				},
				defaultType : 'textfield',
				items : [ {
					xtype : 'hidden',
					name : 'id'
				}, {
					fieldLabel : '单位工程名称',
					name : 'name',
					allowBlank : false
				}, {
					fieldLabel : '单位编号',
					name : 'code'
				}, {
					  
					fieldLabel : '起点桩号',
					name : 'startPegNum'
				}, {
					  
					fieldLabel : '终点桩号',
					name : 'endPegNum'
				}, {
					xtype:'numberfield',   
					fieldLabel : '造价(万元)',
					name : 'cost'
				}, {
					fieldLabel : '工序名称',
					name : 'content'
				}, 
				{
				    store:new Ext.data.ArrayStore({
				        fields: ['value', 'label'],
				        data : <pt:code category="3006" json="true"></pt:code>
				    }),
				    displayField:'label',
				    fieldLabel : '行业等级',
				    valueField :'value',
				    xtype:'combo',
				    name:'techGrade',
				    hiddenName :"techGrade",
		            typeAhead: true,
				    mode: 'local',
				    triggerAction: 'all',
				    lazyRender:true
				},
			    {
					fieldLabel : '所在位置',
					xtype:'textarea',
					name : 'location'
				},{
					xtype:'combo',
					fieldLabel : '是否主要工程',
					name : 'principal',
					store:new Ext.data.ArrayStore({
				        fields: ['value', 'label'],
				        data : [['0','是'],['1','否']]
				    }),
				    displayField:'label',
				    valueField :'value',
				    hiddenName :"principal",
		            typeAhead: true,
				    mode: 'local',
				    triggerAction: 'all',
				    lazyRender:true
				},{
					xtype:'textarea',
					fieldLabel : '备注',
					name : 'remark'
				} ]
			})
			return this.fp;
		}
	});
	
	
	Pengtu.Ext.SubprojectPanel = Ext.extend(Pengtu.Ext.ContractPanel, {
		deleteURL:'${ctx}/project/sub/subproject!delete.action?id=',
		saveURL : '${ctx}/project/sub/subproject!save.action',
		loadURL : '${ctx}/project/sub/subproject!getSubproject.action?id=',
		createForm : function() {
			this.fp = new Ext.FormPanel({
				labelWidth : 100, // label settings here cascade unless overridden
				frame : true,
				id : this.id,
				title : this.title,
				bodyStyle : 'padding:5px 5px 0',
				width : this.width,
				defaults : {
					labelWidth : 100,
					width : 180
				},
				defaultType : 'textfield',
				items : [ {
					xtype : 'hidden',
					name : 'id'
				}, {
					fieldLabel : '分部名称',
					name : 'name',
					allowBlank : false
				}, {
					fieldLabel : '分部编号',
					name : 'code',
					allowBlank : false
				}, {
					  
					fieldLabel : '起点桩号',
					name : 'startPegNum'
				}, {
					  
					fieldLabel : '终点桩号',
					name : 'endPegNum'
				}, {
					xtype:'numberfield',   
					fieldLabel : '造价(万元)',
					name : 'cost'
				}, {
					fieldLabel : '工序名称',
					name : 'content'
				},  {
				    store:new Ext.data.ArrayStore({
				        fields: ['value', 'label'],
				        data : <pt:code category="3006" json="true"></pt:code>
				    }),
				    displayField:'label',
				    fieldLabel : '行业等级',
				    valueField :'value',
				    xtype:'combo',
				    name:'techGrade',
				    hiddenName :"techGrade",
		            typeAhead: true,
				    mode: 'local',
				    triggerAction: 'all',
				    lazyRender:true
				},  {
					fieldLabel : '构建类型',
					name : 'structure'
				},  {
					fieldLabel : '所在位置',
					name : 'location'
				},{
					xtype:'combo',
					fieldLabel : '是否主要工程',
					name : 'principal',
					store:new Ext.data.ArrayStore({
				        fields: ['value', 'label'],
				        data : [['0','是'],['1','否']]
				    }),
				    displayField:'label',
				    valueField :'value',
				    hiddenName :"principal",
		            typeAhead: true,
				    mode: 'local',
				    triggerAction: 'all',
				    lazyRender:true
				},{
					xtype:'textarea',
					fieldLabel : '备注',
					name : 'remark'
				} ]
			})
			return this.fp;
		}
	});
	
	Pengtu.Ext.SubentryPanel = Ext.extend(Pengtu.Ext.ContractPanel, {
		deleteURL:'${ctx}/project/sub/subentry!delete.action?id=',
		saveURL : '${ctx}/project/sub/subentry!save.action',
		loadURL : '${ctx}/project/sub/subentry!getSubentry.action?id=',
		createForm : function() {
			this.fp = new Ext.FormPanel({
				labelWidth : 100, // label settings here cascade unless overridden
				frame : true,
				id : this.id,
				title : this.title,
				bodyStyle : 'padding:5px 5px 0',
				width : this.width,
				defaults : {
					labelWidth : 100,
					width : 180
				},
				defaultType : 'textfield',
				items : [ {
					xtype : 'hidden',
					name : 'id'
				}, {
					fieldLabel : '分项名称',
					name : 'name',
					allowBlank : false
				}, {
					fieldLabel : '分项编号',
					name : 'code'
				}, {
					  
					fieldLabel : '起点桩号',
					name : 'startPegNum'
				}, {
					  
					fieldLabel : '终点桩号',
					name : 'endPegNum'
				}, {
					 xtype:'numberfield', 
					fieldLabel : '造价(万元)',
					name : 'cost'
				}, {
					fieldLabel : '工序名称',
					name : 'content'
				}, {
				    store:new Ext.data.ArrayStore({
				        fields: ['value', 'label'],
				        data : <pt:code category="3006" json="true"></pt:code>
				    }),
				    displayField:'label',
				    fieldLabel : '行业等级',
				    valueField :'value',
				    xtype:'combo',
				    name:'techGrade',
				    hiddenName :"techGrade",
		            typeAhead: true,
				    mode: 'local',
				    triggerAction: 'all',
				    lazyRender:true
				},  {
					fieldLabel : '构建类型',
					name : 'structure'
				},  {
					fieldLabel : '工程位置',
					name : 'location'
				}, {
					xtype:'combo',
					fieldLabel : '是否主要工程',
					name : 'principal',
					store:new Ext.data.ArrayStore({
				        fields: ['value', 'label'],
				        data : [['0','是'],['1','否']]
				    }),
				    displayField:'label',
				    valueField :'value',
				    hiddenName :"principal",
		            typeAhead: true,
				    mode: 'local',
				    triggerAction: 'all',
				    lazyRender:true
				}, {
					xtype:'textarea',
					fieldLabel : '备注',
					name : 'remark'
				} ]
			})
			return this.fp;
		}
	});
	
	Ext.onReady(function() {
	Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = "under";
	var centerPanel = new Ext.ux.tree.TreeGrid(
						{	enableHdMenu: false,
							title : '单位分部分项工程管理',
							region : "center",
							tbar : [ {
								text : '刷新',
								tabIndex : 1,
								handler : searchData,
								iconCls : 'bt_search'
							}, '-', {
								text : '新增图纸标段',
								tabIndex : 2,
								handler : addDrawcontract,
								iconCls : 'bt_add'
							} ],
							columns : [ {
								header : "单位分部分项名称",
								width : 200,
								sortable : true,
								dataIndex : 'name'
							}, {
								  
								header : "起点桩号",
								width : 120,
								sortable : true,
								dataIndex : 'startPegNum'
							}, {
								header : "终点桩号",
								width : 120,
								sortable : true,
								dataIndex : 'endPegNum'
							}],
							contextMenu : new Ext.menu.Menu({
										items : [ {
											id : 'add',
											text : '新增'
										}, '-', {
											id : 'delete',
											text : '刷新'
										} ],
										listeners : {
											itemclick : function(item) {
												switch (item.id) {
												case 'delete':
													centerPanel.root.reload();
													break;
												case 'add':
													var n = item.parentMenu.contextNode;
													var fromPanel = newPanel(n,true);
													fromPanel.showWin();
													break;
												}
											}
										}
									}),
							listeners : {
								contextmenu : function(node, e) {
									node.select();
									var c = node.getOwnerTree().contextMenu;
									c.contextNode = node;
									var id = node.id.split("@")[0];
									if(id<3){
										c.showAt(e.getXY());
									}
								},
								click : function(node, e) {
									var fromPanel = newPanel(node);
									var eastPanel = Ext.getCmp("eastPanel");
									eastPanel.removeAll(true);
									eastPanel.add(fromPanel.onEditPanel());
									eastPanel.doLayout();
								}
							},
							dataUrl : '${ctx}/project/drawcontract!showContract.action?projectId=${param.projectId}'
						});

         	var viewPanel = new Ext.Panel({
         		 layout: 'border',
				 width: 800,
				 height: 500,
				 renderTo :"extOaN",
				 loadmask : true,
				items : [{
					layout : 'border',
					region : "center",
					loadmask : true,	
					items : [centerPanel, {
						id : "eastPanel",
						layout : 'fit',
						width : 350,
						region : "east"
					}]
				}]
				});
/**
 * 刷新树列表
 */
function searchData() {
		centerPanel.root.reload();
	}
/**
 * 增加图纸合同段信息
 */
function addDrawcontract() {
		var fromPanel = new Pengtu.Ext.DrawcontractPanel({
			title : "图纸标段信息",
			fid : "${param.projectId}",
			fparam:'projectId',
			treeGrid : centerPanel
		});
		fromPanel.showWin();
	}
/**
 * 根据树节点获得对应的frompanel
 */
function newPanel(node, isAdd) {
		var idType = node.id;
		var array = idType.split('@');
		var type = new Number(array[0]);
		var id = array[1];
		var fid,did;
		if(isAdd== true){
			fid = id;
			type = type + 1 ;
		} else {
			did = id;
		}
		type = type + "";
		switch (type) {
		case '0':
				var fromPanel = new Pengtu.Ext.DrawcontractPanel({
					title : "图纸标段信息",
					id : did,
					fid : fid,
					treeGrid : centerPanel
				});
			break;
		case '1':
				var fromPanel = new Pengtu.Ext.SubunitPanel({
					title : "标段单位工程信息",
					id : did,
					fid : fid,
					fparam: 'contractId',
					treeGrid : centerPanel
				});
		 break;
		case '2':
			var fromPanel = new Pengtu.Ext.SubprojectPanel({
				title : "标段分部信息",
				id : did,
				fid : fid,
				fparam: 'subunitId',
				treeGrid : centerPanel
			});
	 break;
		case '3':
			var fromPanel = new Pengtu.Ext.SubentryPanel({
				title : "标段分项信息",
				id : did,
				fid : fid,
				fparam: 'subprojectId',
				treeGrid : centerPanel
			});
	     break;
	}
	return fromPanel;
	}
});
</script>
</head>
<body>
<div id="extOaN"></div>
</body>
</html>
